package com.battle.pojo.valid;

import com.battle.pojo.validation.PhoneValidation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author Joseph.Li
 * @author joseph.li@king-v.com
 * Created in 2022-06-28 14:56
 * <p>
 * 校验电话号码注解
 * <p>
 * 有默认规则
 * <p>
 * 可以替换其他规则，比如兼容座机等其他格式
 */
@Documented
@Constraint(validatedBy = PhoneValidation.class)
@Target({FIELD})
@Retention(RUNTIME)
public @interface Phone {

    /**
     * 正则匹配规则
     * <p>
     * 如果不填就读配置
     *
     * @return
     */
    String pattern() default "^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[2-7])|(17[0-8])|(18[0-9])|(19[1-9]))\\d{8}$";



    /**
     * 字段名称
     * <p>
     * 消息前缀的别名
     *
     * @return
     */
    String message() default "手机号码格式错误";



    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};

}
